#include "BlockQueue.hpp"
#include "Task.hpp"
// 生产者线程
void* Producer(void* arg)
{
	BlockQueue<Task>* bq = static_cast<BlockQueue<Task>*>(arg); 
	const char* arr = "+-*/%";
	// 生产线程不断生产数据
	while (true)
    {
        sleep(1);
		int x = rand() % 100;
		int y = rand() % 100;
		char op = arr[rand() % 5];
		Task t(x, y, op);
		// 生产数据
		bq->Push(t); 
	}
}
// 消费者线程
void* Consumer(void* arg)
{
	BlockQueue<Task>* bq = static_cast<BlockQueue<Task>*>(arg);
	// 消费线程不断消费数据
  	while (true)
    {
		sleep(1);
		// 消费数据
		bq->Pop(); 
	}
}

int main()
{
    srand(time(nullptr));
    pthread_t producer, consumer;
    BlockQueue<int>* bq = new BlockQueue<int>;
 
    pthread_create(&producer,nullptr,Producer,bq);
    pthread_create(&consumer,nullptr,Consumer,bq);
 
    pthread_join(producer,nullptr);
    pthread_join(consumer,nullptr);
    delete bq;
    return 0;
}